<?php
/**
 * 匠言知识付费
 * Author: 山西匠言网络科技有限公司
 * This is not a free software, it under the license terms, you can visit https://www.zsffzxkc.cn/ get more details.
 */
namespace app\index\controller;
use think\Db;
class Set extends  Base
{
    public function base_set(){
        $map=array(
          'acid'=>1,
        );
        if(is_table_exist('set')) {
            $data = Db::name('set')
                ->where($map)
                ->find();
            if(isset($data['qrcode']) && $data['qrcode'] != ''){
                $data['qrcode'] = to_media_url($data['qrcode']);
            }
            if(isset($data['wechat']) && $data['wechat'] != ''){
                $data['wechat'] = to_media_url($data['wechat']);
            }
            if($data['kefu_uid'] != ''){
                $kefu = db('user')->where(['acid'=>1,'id'=>$data['kefu_uid']])->field('nickname,avatar,id as uid,openid')->find();
                if(!empty($kefu)){
                    $data['kefuinfo'] = $kefu;
                }
            }
        }
        if(is_table_exist('set_smallapp')) {
            $smallapp = Db::name('set_smallapp')
                ->where($map)
                ->find();
            if (!empty($smallapp)) {
                $data['smallapp'] = $smallapp;
            }
        }
        if(is_table_exist('set_app')) {
            $app = Db::name('set_app')
                ->where($map)
                ->find();
            if (!empty($app)) {
                $data['app'] = $app;
            }
        }
        if(is_table_exist('set_h5')) {
            $h5=Db::name('set_h5')
                ->where($map)
                ->find();
            if(!empty($h5)){
                $data['h5']=$h5;
                $data['h5']['gzh_qrcode'] = to_media_url($h5['gzh_qrcode']);
            }
        }
        if(is_table_exist('set_jigou')) {
            $jigou = Db::name('set_jigou')
                ->where($map)
                ->find();
            if (!empty($jigou)) {
                $data['jigou'] = $jigou;
            }
        }
        if(is_table_exist('set_diypage')){
            $diypage = db('set_diypage')->where(['acid'=>1])
                ->find();
            if(!empty($diypage)){
                $data['diypage']=json_decode($diypage['data'],true);
            }
        }
        if(is_table_exist('set_pc')){
            $pc=Db::name('set_pc')
                ->where($map)
                ->find();
            if(!empty($pc)){
                $data['pc']=$pc;
            }
        }
        $this->result(0,'获取基础设置数据成功',$data,0,'json');
    }
}
